So i tried to solve this problem by doing
document.getElementbyId('seach_input') but it doesnt work
here my code:
var autocomplete = new google.maps.places.Autocomplete(document.getElementById("search_input"),
{
componentRestrictions: {'country' : ['AT']},
fields: ['geometry', 'name'],
types: ['establishment', 'geocode']
})
var directionsService = new google.maps.DirectionsService();
var request = {
origin : 'Imst, Österreich', // a city, full address, landmark etc
destination : 'Innsbruck, Österreich',
travelMode : google.maps.DirectionsTravelMode.DRIVING
};
function getRoute(){
directionsService.route(request, function(response, status) {
if ( status == google.maps.DirectionsStatus.OK ) {
document.getElementById('preis').value = Math.round(response.routes[0].legs[0].distance.value / 1000 * 2) // the distance in metres
}
else {
// oops, there's no route between these two locations
// every time this happens, a kitten dies
// so please, ensure your address is formatted properly
}
});
}
<input type="text" required="" class="inputText" id="search_input" name="o" placeholder="Abholort"> <br>
<input type="text" name="preis" readonly="" class="inputText" id="preis" placeholder="preis"><br>
<button id="preisA" onclick="getRoute()" class="toggle-btn">Preis ausrechnen!</button>
i want in var request the origin text to be de value of the input text with the id "search_input" how can i do it?